﻿using DosTexPrj.Core.Models;
using FluentNHibernate.Mapping;

namespace DosTexPrj.Implement.NHibernate.Mapping
{
    public class KnittingOrderMapping : ClassMap<KnittingOrder>
    {
        public KnittingOrderMapping()
        {
            Table("KnittingOrders");
            Id(x => x.Id, "KnittingOrderID").UnsavedValue(0).GeneratedBy.Identity();
            References<Order>(x => x.BelongToOrder).Column("OrderID").Not.LazyLoad();
            References<Supplier>(x => x.BelongToSupplier).Column("SupplierID").Not.LazyLoad();
            References<Composition>(x => x.Composition).Column("CompostionID").Not.LazyLoad();
            References<FabricType>(x => x.FabricType).Column("FabricTypeID").Not.LazyLoad();
            References<OrderStatus>(x => x.OrderStatus).Column("OrderStatusID").Not.LazyLoad();
            Map(x => x.BelongToKnittingOrderId, "BelongToKnittingOrderId").Default("0");
            Map(x => x.DeliveryAddress, "DeliveryAddress").Not.Nullable().Length(200);
            Map(x => x.OrderDate).Not.Nullable();
            Map(x => x.LenghtOfYarnPer100Needles).Not.Nullable();
            Map(x => x.WhaleCourse).Not.Nullable(); ;
            Map(x => x.KnittingMachine).Not.Nullable(); ;
            Map(X => X.Gauge).Not.Nullable(); ;
            Map(x => x.Diameter).Not.Nullable(); ;
            Map(x => x.FabricWeight).Not.Nullable(); ;
            Map(x => x.ECRUWeight).Not.Nullable(); ;
            Map(x => x.ECRUWidth).Not.Nullable(); ;
            Map(x => x.FinishEstimatedWeight).Not.Nullable(); ;
            Map(x => x.FinishEstimatedWidth).Not.Nullable(); ;
            HasMany<KnittingOrderDetail>(x => x.Details).Cascade.AllDeleteOrphan()
                                                        .KeyColumn("KnittingOrderID")
                                                        .Not.LazyLoad().AsBag();
        }
    }
}